package com.zj.demo01.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zj.demo01.dto.AirDTO;
import com.zj.demo01.entity.Air;
import com.zj.demo01.entity.District;
import com.zj.demo01.mapper.AirMapper;
import com.zj.demo01.mapper.DistrictMapper;
import com.zj.demo01.service.AirService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName:AirService
 * @author:[开发者名称]
 * @Description:[类的功能描述]
 * @Date:2025/9/3/12:59
 * @Version:1.0
 */
@Service
public class AirServiceImpl implements AirService {
    @Autowired
    private DistrictMapper districtMapper;
    @Autowired
    private AirMapper airMapper;

    /**
     * 查询district表中所有数据
     * @return
     */
    @Override
    public List<District> districtList() {
        List<District>  list = districtMapper.districtList();
        return list;
    }

    @Override
    public PageInfo findAirBydistrictIdAndPage(Integer page, Integer size, Integer districtID) {
        //从那条记录开始查 到哪里 每页显示多少数据  查询条件是什么
        PageHelper.startPage(page,size);
        List<Air> list= airMapper.findBydistrictID();
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public void airAdd(AirDTO airDTO) {
        Air air = new Air();
        BeanUtils.copyProperties(airDTO,air);
        int count = airMapper.insert(air);
        if(count!=1){
            System.out.println("空气添加添加失败");
            throw new RuntimeException("空气添加添加失败");
        }

    }

    @Override
    public int updateById(Air air) {
        int cont = airMapper.updateById(air);
        return 0;
    }

    @Override
    public void deleteByID(Integer id) {
        int i = airMapper.deleteByID(id);
    }
}
